﻿using System;
using System.Diagnostics;
using System.IO;
using Lucene.Net.Store;

namespace LuceneSearch.Indexer
{
    class Program
    {
        static void Main(string[] args)
        {
            var indexDir = args[0];
            var dataDir = args[1];

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            var fsDirectory = FSDirectory.GetDirectory(indexDir, true);
            var indexWriter = new BufferedLuceneIndexWriter(fsDirectory);

            new DirectoryTraverser().Traverse(
                new DirectoryInfo(dataDir), 
                new DirectoryIndexer(indexWriter));
            
            var indexedDocs = indexWriter.GetDocumentCount();

            indexWriter.Optimize();
            indexWriter.Close();

            Console.WriteLine("Indexed {0} documents in {1} seconds", indexedDocs, stopwatch.Elapsed.TotalSeconds);
        }
    }
}
